<<<<<<< .mine
package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

import TouristManagement.DateV;

import util.Convert;

public class TouristDAO {

	private MySqlConnecte myConn = new  MySqlConnecte();
	
	//Ajouter un nouveau touriste
	public short addTourist(String name, Date dateStart, Date dateEnd){
		try{
			final String query = "INSERT INTO touriste (nom,dateIN,dateOUT) VALUES (?,?,?)";
			PreparedStatement preparedQuery = this.myConn.getConnection().prepareStatement(query,Statement.RETURN_GENERATED_KEYS);
			preparedQuery.setString(1, name);
			preparedQuery.setDate(2, Convert.dateToDateSQL(dateStart));
			preparedQuery.setDate(3, Convert.dateToDateSQL(dateEnd));
			preparedQuery.executeUpdate();
			final ResultSet res = preparedQuery.getGeneratedKeys();
			res.first();
			res.getInt(1);
			return (short)res.getInt(1);
		}
		catch(Exception e){
			e.printStackTrace(System.err);
			return -1;
		}
	}
	
	//getDateStartValidate de la carte de touriste
	public DateV getDateStartValidate(int idTourist){
		try{
			final String queryOrdre = "SELECT dateIn FROM Touriste WHERE idTouriste=?";
			PreparedStatement preparedQuery = this.myConn.getConnection().prepareStatement(queryOrdre);
			preparedQuery.setInt(1, idTourist);
			final ResultSet res = preparedQuery.executeQuery();
			res.first();
			Date dt = res.getDate(1);
			System.out.println(dt);
			return 	Convert.dateToDateV(dt);
		
		}
		catch(Exception e){
			e.printStackTrace(System.err);
			return null;
		}		
	}

	//getDateFinValidate de la carte de touriste
	public DateV getDateFinValidate(int idTourist){
		try {
			final String queryOrdre = "SELECT dateOUT FROM Touriste WHERE idTouriste=?";
			PreparedStatement preparedQuery = this.myConn.getConnection().prepareStatement(queryOrdre);
			preparedQuery.setInt(1, idTourist);
			final ResultSet res = preparedQuery.executeQuery();
			res.first();
			Date dt = res.getDate(1);
			return 	Convert.dateToDateV(dt);
		
		}
		catch(Exception e){
			e.printStackTrace(System.err);
			return null;
		}		
	}
	

	
//	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		TouristDAO tD = new TouristDAO();
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//		Date dateS= sdf.parse("2013-06-08");
//		
//		Date dateS = new Date();
//		Date dateE = new Date();
//	
//		tD.addTourist("MICHEL", dateS, dateE);
//		tD.getDateStartValidate(1);
//		System.out.println(Convert.dateToSQL(dateS));
//		
//	}

}
=======
package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

import TouristManagement.DateV;

import util.Convert;

public class TouristDAO {

	private MySqlConnecte myConn = new  MySqlConnecte();
	
	public short addTourist(String name, Date dateStart, Date dateEnd)
	{
		try
		{
			final String query = "insert into TOURISTE (NOM,DATEIN,DATEOUT) values (?,?,?)";
			PreparedStatement preparedQuery = this.myConn.getConnection().prepareStatement(query,Statement.RETURN_GENERATED_KEYS);
			preparedQuery.setString(1, name);
			preparedQuery.setDate(2, Convert.dateToSQL(dateStart));
			preparedQuery.setDate(3, Convert.dateToSQL(dateEnd));
			preparedQuery.executeUpdate();
			final ResultSet res = preparedQuery.getGeneratedKeys();
			res.first();
			res.getInt(1);
			return (short)res.getInt(1);
		}
		catch(Exception e)
		{
			e.printStackTrace(System.err);
			return -1;
		}
	}
	
	//getDateStartValidate
	public DateV getDateStartValidate(int idTourist){
		try
		{
			final String queryOrdre = "SELECT dateIn FROM Tourist WHERE idTouriste=?";
			PreparedStatement preparedQuery = this.myConn.getConnection().prepareStatement(queryOrdre);
			preparedQuery.setInt(1, idTourist);
			final ResultSet res = preparedQuery.executeQuery();
			res.first();
			Date dt = res.getDate(1);
			return 	Convert.dateToDateV(dt);
		
		}
		catch(Exception e)
		{
			e.printStackTrace(System.err);
			return null;
		}		
	}

	//getDateFinValidate
	public DateV getDateFinValidate(int idTourist){
		try
		{
			final String queryOrdre = "SELECT dateOUT FROM Tourist WHERE idTouriste=?";
			PreparedStatement preparedQuery = this.myConn.getConnection().prepareStatement(queryOrdre);
			preparedQuery.setInt(1, idTourist);
			final ResultSet res = preparedQuery.executeQuery();
			res.first();
			Date dt = res.getDate(1);
			return 	Convert.dateToDateV(dt);
		
		}
		catch(Exception e)
		{
			e.printStackTrace(System.err);
			return null;
		}		
	}
	
	public boolean existTourist(short idTouriste) {
		//vérifier si le tourist existe dans la base
		try
		{
			final String queryOrdre = "SELECT COUNT(*) FROM touriste WHERE idTouriste=?";
			PreparedStatement preparedQuery = this.myConn.getConnection().prepareStatement(queryOrdre);
			preparedQuery.setInt(1, idTouriste);
			final ResultSet res = preparedQuery.executeQuery();
			res.first();
			final int compte = res.getInt(1);
			return 	(compte==1);		
		}
		catch(Exception e)
		{
			e.printStackTrace(System.err);
			return false;
		}		
	}	
	

	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TouristDAO tD = new TouristDAO();
		Date dateS = new Date();
		Date dateE = new Date();
	
		System.out.println(tD.existTourist((short)9));
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//		Date dateS= sdf.parse("2013-06-08");
//		
//		
//		Date dateE = new Date();
//	
//		System.out.println(tD.addTourist("NGUYEN", dateS, dateE));
//		System.out.println(Convert.dateToSQL(dateS));
		
	}

}
>>>>>>> .r157
